home *** CD-ROM | disk | FTP | other *** search
/ Mac100% 1998 November / MAC100-1998-11.ISO.7z / MAC100-1998-11.ISO / オンラインソフト定点観測 / ユーティリティ / Mops 3.2.sea / Mops 3.2 / Mops source / More classes / Bytestring < prev    next >
Text File  |  1991-06-23  |  3KB  |  175 lines

  1. ¥ The class Bytestring adds further methods to the class String+.
  2. ¥ These methods allow various numbers of bytes to be fetched from
  3. ¥ or stored to the current position of the bytestring, with the
  4. ¥ current position being updated.  Any data can be stored in these bytes -
  5. ¥ not necessarily Ascii characters.
  6.  
  7. :class  BYTESTRING  super{ string+ }
  8.  
  9. :mcode 1STW:        ¥ ( -- n )
  10.     loc
  11.     BSR    dic[getit]
  12.     SUBQ    #2,D0
  13.     BGE.S    ok
  14.     JMP    dic[$fail]
  15. ok    MOVEQ    #0,D1
  16.     MOVE.W    (A0),D1
  17.     PUSH    D1
  18. ;mcode
  19.  
  20. :mcode 1STL:        ¥ ( -- n )
  21.     loc
  22.     BSR    dic[getit]
  23.     SUBQ    #4,D0
  24.     BGE.S    ok
  25.     JMP    dic[$fail]
  26. ok    MOVEQ    #0,D1
  27.     MOVE    (A0),D1
  28.     PUSH    D1
  29. ;mcode
  30.  
  31. :mcode >1ST:        ¥ ( c -- )
  32.     loc
  33.     BSR    dic[getit]
  34.     BNE.S    ok
  35.     JMP    dic[$fail]
  36. ok    POP    D1
  37.     MOVE.B    D1,(A0)
  38. ;mcode
  39.  
  40. :mcode >1STW:        ¥ ( w -- )
  41.     loc
  42.     BSR    dic[getit]
  43.     SUBQ    #2,D0
  44.     BGE.S    ok
  45.     JMP    dic[$fail]
  46. ok    POP    D1
  47.     MOVE.W    D1,(A0)
  48. ;mcode
  49.  
  50. :mcode >1STL:        ¥ ( w -- )
  51.     loc
  52.     BSR    dic[getit]
  53.     SUBQ    #4,D0
  54.     BGE.S    ok
  55.     JMP    dic[$fail]
  56. ok    POP    D1
  57.     MOVE    D1,(A0)
  58. ;mcode
  59.  
  60. :mcode OFFSC:        ¥ ( n -- c )
  61.     BSR    dic[getit]
  62.     MOVEQ    #0,D1
  63.     ADD    (SP),A0
  64.     MOVE.B    (A0),D1
  65.     MOVE    D1,(SP)
  66. ;mcode
  67.  
  68. :mcode >OFFSC:        ¥ ( c n -- )
  69.     BSR    dic[getit]
  70.     ADD    (SP)+,A0
  71.     POP    D1
  72.     MOVE.B    D1,(A0)
  73. ;mcode
  74.  
  75.  
  76. :mcode NXTC:        ¥ ( -- c )
  77.     loc
  78.     BSR    dic[getit]
  79.     BNE.S    ok
  80.     JMP    dic[$fail]
  81. ok    MOVEQ    #0,D1
  82.     MOVE.B    (A0),D1
  83.     ADDQ    #1,8(A2)
  84.     PUSH    D1
  85. ;mcode
  86.  
  87. :m NXTW:
  88.     1stW: self  2 skip: self  ;m
  89.  
  90. :m NXTL:
  91.     1stL: self  4 skip: self  ;m
  92.  
  93. :m NXTN:  { n -- n' }
  94.     get: self  n >=
  95.     IF    0 swap  n bounds DO  8 << i c@ or  LOOP
  96.         n skip: self
  97.     ELSE    drop 0
  98.     THEN  ;m
  99.  
  100.  
  101. :m >NXTC:           ¥ ( c -- )
  102.     >1st: self  1 skip: self  ;m
  103.  
  104. :m >NXTW:           ¥ ( n -- )
  105.     >1stW: self  2 skip: self  ;m
  106.  
  107. :m >NXTL:
  108.     >1stL: self  4 skip: self  ;m
  109.  
  110. :m >NXT$:       ¥ ( addr len -- )
  111.     ovwr: self  ;m
  112.  
  113. :m >NXTN:  { val n  -- }
  114.     val pad !
  115.     4 n - pad +  n  >nxt$: self  ;m
  116.     
  117.  
  118. :m +C:        ¥ ( c -- )
  119.     +: self   ;m
  120.  
  121. :m +W:        ¥ ( n -- )
  122.     pad w!  pad 2  add: self  ;m
  123.  
  124. :m +L:        ¥ ( n -- )
  125.     pad !   pad 4  add: self  ;m
  126.  
  127. :m +N:  { n cnt -- }
  128.     n  32  cnt 2* 4* -  <<  pad !
  129.     pad cnt  add: self  ;m
  130.  
  131.  
  132. :mcode COUNT:    ¥ Assumes the substring starting at POS is a
  133.         ¥ counted string, and sets POS and LIM to delimit it.
  134.         ¥ Note: ignores the initial value of LIM, which
  135.         ¥ hardly matters anyway.  (It was easy to forget to do
  136.         ¥ NOLIM:, until I changed this.)
  137.  
  138.     MOVE    4(A2),12(A2)    ; nolim: self
  139.     BSR    dic[getit]
  140.     MOVEQ    #0,D0
  141.     MOVE.B    (A0),D0
  142.     ADDQ    #1,8(A2)
  143.     ADD    8(A2),D0
  144.     MOVE    D0,12(A2)
  145. ;mcode
  146.  
  147. :mcode WCOUNT:    ¥ As for COUNT:, but with a 2-byte length, maybe non-aligned.
  148.  
  149.     MOVE    dic[big#],12(A2)    ; Set LIM to a big number
  150.     BSR    dic[getit]
  151.     MOVEQ    #0,D0
  152.     MOVE.B    (A0),D0
  153.     LSL.W    #8,D0
  154.     MOVE.B    1(A0),D0
  155.     ADDQ    #2,8(A2)
  156.     ADD    8(A2),D0
  157.     MOVE    D0,12(A2)
  158. ;mcode
  159.  
  160. ;class
  161.  
  162. :code    2B@        ¥ ( addr -- n )  2-byte fetch, non-aligned.
  163.     MOVE    (SP),A0
  164.     CLR    (SP)
  165.     MOVE.B    (A0)+,2(SP)
  166.     MOVE.B    (A0),3(SP)
  167. ;code
  168.  
  169. :code    2B!        ¥ ( addr n -- )  2-byte store.
  170.     MOVE    (SP)+,A0
  171.     MOVE.B    2(SP),(A0)+
  172.     MOVE.B    3(SP),(A0)+
  173.     ADDQ    #4,SP
  174. ;code
  175.